<?php 
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: checkout_register_form.php 1612 2009-01-22 20:11:25Z thepisu $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
mm_showMyFileName( __FILE__ );
global $mosConfig_allowUserRegistration, $mosConfig_useractivation;
require_once( CLASSPATH . "ps_userfield.php" );
require_once( CLASSPATH . "ps_checkout.php" );

$ps_checkout = new ps_checkout;

require_once( CLASSPATH . "htmlTools.class.php" );
$missing = vmGet( $_REQUEST, "missing", "" );

if (!empty( $missing )) {
	echo "<script type=\"text/javascript\">alert('".$VM_LANG->_('CONTACT_FORM_NC',false)."'); </script>\n";
}

// If not using NO_REGISTRATION, redirect with a warning when Joomla doesn't allow user registration
if ($mosConfig_allowUserRegistration == "0" && VM_REGISTRATION_TYPE != 'NO_REGISTRATION' ) {
	$msg = $VM_LANG->_('USER_REGISTRATION_DISABLED');
	vmRedirect( $sess->url( 'index.php?page='.HOMEPAGE, true, false ), $msg );
	return;
}

if( vmIsJoomla( '1.5' ) ) {
	// Set the validation value
	$validate = JUtility::getToken();
} else {
	$validate =  function_exists( 'josspoofvalue' ) ? josSpoofValue(1) : vmSpoofValue(1);
}

$fields = ps_userfield::getUserFields('registration', false, '', false );
// Read-only fields on registration don't make sense.
foreach( $fields as $field ) $field->readonly = 0;
$skip_fields = array();

if ( $my->id > 0 || (VM_REGISTRATION_TYPE != 'NORMAL_REGISTRATION' && VM_REGISTRATION_TYPE != 'OPTIONAL_REGISTRATION' 
								&& ( $page == 'checkout.index' || $page == 'shop.registration' ) ) ) {
	// A listing of fields that are NOT shown
	$skip_fields = array( 'username', 'password', 'password2' );
	if( $my->id ) {
		$skip_fields[] = 'email';
	}
}

// This is the part that prints out ALL registration fields!


/*echo '
<div align="center">';
    
	if( !$mosConfig_useractivation && @VM_SHOW_REMEMBER_ME_BOX && VM_REGISTRATION_TYPE == 'NORMAL_REGISTRATION' ) {
		echo '<input type="checkbox" name="remember" value="yes" id="remember_login2" checked="checked" />
		<label for="remember_login2">'. $VM_LANG->_('REMEMBER_ME') .'</label><br /><br />';
	}
	else {
		if( VM_REGISTRATION_TYPE == 'NO_REGISTRATION' ) {
			$rmbr = '';
		} else {
			$rmbr = 'yes';
		}
		echo '<input type="hidden" name="remember" value="'.$rmbr.'" />';
	}
	echo '
		<input type="submit" value="'. $VM_LANG->_('BUTTON_SEND_REG') . '" class="button" onclick="return( submitregistration());" />
	</div>
	<input type="hidden" name="Itemid" value="'. $sess->getShopItemid() .'" />
	<input type="hidden" name="gid" value="'. $my->gid .'" />
	<input type="hidden" name="id" value="'. $my->id .'" />
	<input type="hidden" name="user_id" value="'. $my->id .'" />
	<input type="hidden" name="option" value="com_virtuemart" />
	<input type="hidden" name="' . $validate . '" value="1" />
	<input type="hidden" name="useractivation" value="'. $mosConfig_useractivation .'" />
	<input type="hidden" name="func" value="shopperadd" />
	<input type="hidden" name="page" value="checkout.index" />
	</form>';*/

?>
<script type="text/javascript">
$(document).ready(function(){

	jQuery("#btn-other-shipping").click(function(){
		var status = jQuery("#other-shipping-status").attr("value");
		if(status == "0"){ jQuery("#other-shipping-status").attr("value","1"); }
		else { jQuery("#other-shipping-status").attr("value","0"); }
		//alert(jQuery("#other-shipping-status").attr("value"));
	});

	validateEmail = function(email) 
	{ 
		 var x=email;
		 var atpos=x.indexOf("@");
		 var dotpos=x.lastIndexOf(".");
		 if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
		 {
		   return false;
		 }
		 return true;
	};

	validate_form = function(){
		var flag = true;
		//alert(jQuery("#first_name_field").attr("value"));
		if(jQuery("#first_name_field").attr("value")==""){
			jQuery("#alert").html("Please enter first name");
			jQuery('#backoverlay').show();
			jQuery('#show_popup').show();
			flag = false;
		}else{
			if(jQuery("#last_name_field").attr("value")==""){
				jQuery("#alert").html("Please enter last name");
				jQuery('#backoverlay').show();
				jQuery('#show_popup').show();
				flag = false;
			}else{
				if(jQuery("#address_1_field").attr("value")==""){
					jQuery("#alert").html("Please enter address");
					jQuery('#backoverlay').show();
					jQuery('#show_popup').show();
					flag = false;
				}else{
					if(jQuery("#city_field").attr("value")==""){
						jQuery("#alert").html("Please enter city");
						jQuery('#backoverlay').show();
						jQuery('#show_popup').show();
						flag = false;
					}else{
						if(jQuery("#phone_1_field").attr("value")==""){
							jQuery("#alert").html("Please enter phone");
							jQuery('#backoverlay').show();
							jQuery('#show_popup').show();
							flag = false;
						}else{
							if(validateEmail(jQuery("#email_field").attr("value")) == false){
								jQuery("#alert").html("Please enter email");
								jQuery('#backoverlay').show();
								jQuery('#show_popup').show();
								flag = false;
							}else{
								//alert(jQuery("#div-shipping #first_name_field").attr("value"));
								//--------------------------------------------------------//
								if(jQuery("#other-shipping-status").attr("value")=="1"){
									if(jQuery("#div-shipping #first_name_field").attr("value")==""){
										jQuery("#alert").html("Please enter first name");
										jQuery('#backoverlay').show();
										jQuery('#show_popup').show();
										flag = false;
									}else{
										if(jQuery("#div-shipping #last_name_field").attr("value")==""){
											jQuery("#alert").html("Please enter last name");
											jQuery('#backoverlay').show();
											jQuery('#show_popup').show();
											flag = false;
										}else{
											if(jQuery("#div-shipping #address_1_field").attr("value")==""){
												jQuery("#alert").html("Please enter address");
												jQuery('#backoverlay').show();
												jQuery('#show_popup').show();
												flag = false;
											}else{
												if(jQuery("#div-shipping #city_field").attr("value")==""){
													jQuery("#alert").html("Please enter city");
													jQuery('#backoverlay').show();
													jQuery('#show_popup').show();
													flag = false;
												}else{
													if(jQuery("#div-shipping #phone_1_field").attr("value")==""){
														jQuery("#alert").html("Please enter phone");
														jQuery('#backoverlay').show();
														jQuery('#show_popup').show();
														flag = false;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		//alert(flag);
		if(flag == true){
			if(jQuery("#agree-term").is(':checked') == false){
				//alert("?????????");
				jQuery("#alert").html("Please agree with our term of service");
				jQuery('#backoverlay').show();
				jQuery('#show_popup').show();
				flag = false;
			}
		}
		
		return flag;
	}
	//formSubmit
	jQuery('input[name|="formSubmit"]').hide();
	jQuery("#btn-other-shipping").click(function(){
		jQuery("#otherAddress123").toggle();
	});
	
	jQuery(".inputbox").attr("class","orderField");
	jQuery("h3").attr("style","display:none;");
	jQuery("h4").attr("style","display:none;");
	//$("h2").attr("style","display:none;");
	var mytotal = "0";
	var mysubtotal = "0";
	jQuery('#ha-basket').load('index2.php?option=com_virtuemart&page=shop.cart&type=1',function(){
		mytotal = jQuery("#b2b-order-total").attr("value");
		mysubtotal = jQuery("#b2b-subtotal_display").attr("value");
		//alert(mysubtotal);
		jQuery("#hidden-total").attr("value",mytotal);
		jQuery("#hidden-subtotal").attr("value",mytotal);
		
	});
	
	
	
	jQuery('#bt_tilBetaling').click(function(){
		var company = jQuery("#company_field").attr("value");
		var first_name = jQuery("#first_name_field").attr("value");
		var last_name = jQuery("#last_name_field").attr("value");
		var address_1 = jQuery("#address_1_field").attr("value");
		var city = jQuery("#city_field").attr("value");
		var country = jQuery("#country_field").attr("value");
		var phone_1 = jQuery("#phone_1_field").attr("value");
		var email = jQuery("#email_field").attr("value");
		var temp = jQuery("#shopperAdd").val();
		var func = "shopperAdd";
		var func_1 = "userAddressAdd"; 
		if(temp != "") { 
			func = "shopperUpdate";
			func_1 = "userAddressUpdate"; 

		};
		if( validate_form() == true )
		{
			
			var ha_opt = "index2.php?option=com_virtuemart&page=checkout.index&func="+func+"&first_name="+first_name+"&last_name="+last_name+"&company="+company+"&address_1="+address_1+"&country="+country+"&city="+city+"&phone_1="+phone_1+"&email="+email;
			jQuery('#ha-temp').load(ha_opt, function(){
				
				jQuery("#shopperAdd").attr("value","1");
				company = jQuery("#div-shipping #company_field").attr("value");
				first_name = jQuery("#div-shipping #first_name_field").attr("value");
				last_name = jQuery("#div-shipping #last_name_field").attr("value");
				address_1 = jQuery("#div-shipping #address_1_field").attr("value");
				city = jQuery("#div-shipping #city_field").attr("value");
				country = jQuery("#div-shipping #country_field").attr("value");
				phone_1 = jQuery("#div-shipping #phone_1_field").attr("value");
				email = jQuery("#div-shipping #email_field").attr("value");
				ship_rate_id = "";
				jQuery('#user_id').load("index2.php?option=com_virtuemart&page=shop.getuserid",function(){
					
					var t1 = jQuery('#user_id').html().split(">");
					
					var t2 = t1[1].replace("</div", "");
					
					t2 = t2.replace("</DIV", "");
					//alert(t2);
					var user_id = t2.replace("\n", "").replace("</div", "");
					
					jQuery("#hidden-userid").attr("value",user_id);
					//alert('1');
					var ha_opt_1 = "index2.php?option=com_virtuemart&page=checkout.index&func="+func_1+"&address_type_name=a&address_type=a&first_name="+first_name+"&last_name="+last_name+"&company="+company+"&address_1="+address_1+"&country="+country+"&city="+city+"&phone_1="+phone_1+"&user_id="+user_id;
					alert(ha_opt_1);
					if(jQuery("#other-shipping-status").attr("value")=="1"){
						//alert('2');
						jQuery('#ha-temp').load(ha_opt_1,function(){	
							jQuery('input[name|="shipping_rate_id"]').each(function (i) {
								if(jQuery(this).is(':checked') == true){
									ship_rate_id = jQuery(this).attr("value");
								}
							});
							jQuery("#hidden-ship_rate_id").attr("value",ship_rate_id);
							//alert(ship_rate_id);
							jQuery('#shipto_info').load("index2.php?option=com_virtuemart&page=shop.getshiptoinfo",function(){
								alert('3');
								var v1 =  jQuery('#shipto_info').html().split(">");
								var v2 =  v1[1].replace("</div", "");
								v2 =  v2.replace("</DIV", "");
								var ship_to_info_id = v2.replace("\n", "");
								
								alert(ship_to_info_id);
								jQuery("#hidden-ship_to_info_id").attr("value",ship_to_info_id);
								var ha_opt_2 = "index2.php?option=com_virtuemart&page=checkout.index&func=checkoutProcess&payment_method_id=0&ship_to_info_id="+ship_to_info_id+"&shipping_rate_id=" + ship_rate_id + "&user_id=" + user_id + "&zone_qty=1&checkout_last_step=2&checkout_this_step[]=CHECK_OUT_GET_SHIPPING_METHOD" ;
								jQuery('#ha-temp').load(ha_opt_2, function(){
									/*jQuery("#checkoutForm").submit(function(){
										alert("submit called");
									});*/
									//alert(jQuery("#checkoutForm"));
									//alert(shipping_rate_id);
									var ha_opt_3 = "index.php?option=com_virtuemart&page=checkout.quickpay&checkout_last_step=4&checkout_this_step[]=CHECK_OUT_GET_FINAL_CONFIRMATION&customer_note=&func=checkoutProcess&payment_method_id=2&user_id="+user_id+"&ship_to_info_id="+ship_to_info_id+"&shipping_rate_id="+ship_rate_id+"&zone_qty=1&total="+mytotal+"&subtotal="+mysubtotal;
									//alert(ha_opt_3);
									window.location = ha_opt_3 ;
								});
							});
						});
					}else{
						jQuery('input[name|="shipping_rate_id"]').each(function (i) {
							if(jQuery(this).is(':checked') == true){
								ship_rate_id = jQuery(this).attr("value");
							}
						});
						jQuery("#hidden-ship_rate_id").attr("value",ship_rate_id);
						//alert(ship_rate_id);
						jQuery('#shipto_info').load("index2.php?option=com_virtuemart&page=shop.getshiptoinfo",function(){
							var ship_to_info_id = jQuery('#shipto_info').html().substring(21,54).replace("\n", "");
							jQuery("#hidden-ship_to_info_id").attr("value",ship_to_info_id);
							var ha_opt_2 = "index2.php?option=com_virtuemart&page=checkout.index&func=checkoutProcess&payment_method_id=0&ship_to_info_id="+ship_to_info_id+"&shipping_rate_id=" + ship_rate_id + "&user_id=" + user_id + "&zone_qty=1&checkout_last_step=2&checkout_this_step[]=CHECK_OUT_GET_SHIPPING_METHOD" ;
							jQuery('#ha-temp').load(ha_opt_2, function(){
								/*jQuery("#checkoutForm").submit(function(){
									alert("submit called");
								});*/
								//alert(jQuery("#checkoutForm"));
								//alert(shipping_rate_id);
								var ha_opt_3 = "index.php?option=com_virtuemart&page=checkout.quickpay&checkout_last_step=4&checkout_this_step[]=CHECK_OUT_GET_FINAL_CONFIRMATION&customer_note=&func=checkoutProcess&payment_method_id=2&user_id="+user_id+"&ship_to_info_id="+ship_to_info_id+"&shipping_rate_id="+ship_rate_id+"&zone_qty=1&total="+mytotal+"&subtotal="+mysubtotal;
								//alert(ha_opt_3);
								//window.location = ha_opt_3 ;
							});
						});
					}
				});
			});
		}
	});
});
</script>

<div id="user_id" style="display:none;"></div>
<div id="shipto_info" style="display:none;"></div>
<input type="hidden" value="" id="shopperAdd" />
<input id="other-shipping-status" type="hidden" value="0" />
<div class="containerUnder">
	<div class="orderLeft">
		<div class="mainTitle">Bestilling</div>
        <div class="orderTitle"><span>1</span>Fakturaadresse </div>
		<?php ps_userfield::listUserFields( $fields, $skip_fields ); ?>
		<a id="btn-other-shipping" class="float-right btn address-switch"><img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/other_address_btn.jpg" alt="Skal varene leveres til en anden adresse ?" /></a>
		<div id="otherAddress123" class="input-set" style="display:none;">
			<div class="space10 clr"></div>
			<div id="div-shipping">
			<?php 
				$shipping_fields = ps_userfield::getUserFields( 'shipping' ); 
				ps_userfield::listUserFields( $shipping_fields, $skip_fields ); 
			?>
			</div>
		</div>
	</div>
	<div class="orderCenter">
		
		<div class="orderTitle"><span>2</span>Leveringsmåde</div>
		<div class="orderSubTitle">Levering og håndtering</div>
		<?php 
			$theme = new $GLOBALS['VM_THEMECLASS']();
			echo $theme->fetch( 'checkout/get_shipping_method.tpl.php');
		?>
		<div class="orderTitle"><span>3</span>Betalingsmåde</div>
		Kredit kort<br/>
		Du har valgt at betale for ordren online. Lige så snart du har gennemført din ordre, skal du gennemføre din betaling. Din ordre vil ikke være registreret hos os før du har betalt.<br/><br/>
		
		Du kan betale med følgende betalingskort: <br/>
		<img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/cart_DK.png" alt=""/><img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/cart_visa.png" alt=""/><img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/cart_visa1.png" alt=""/><img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/cart_master.png" alt=""/><img src="images/cart_master1.png" alt=""/>
	</div>
	<div class="orderRight">
		<div class="orderTitle"><span>4</span>Ordreoversigt</div>
		<div id="ha-basket"></div>
		<div class="orderInfo">
			<input id="agree-term" type="checkbox"/> <a data-reveal-id="myModal1" class="link-btn"  href="#">Jeg accepterer forretningsbetingelserne</a>
			<div id="myModal1" class="reveal-modal">
						 <p>Welcome to the Dummy Text Generator!
							This handy tool helps you create dummy text for all your layout needs.
							We are gradually adding new functionality and we welcome your suggestions and feedback.
							Please feel free to send us any additional dummy texts.</p>
						<p>Welcome to the Dummy Text Generator!
							This handy tool helps you create dummy text for all your layout needs.
							We are gradually adding new functionality and we welcome your suggestions and feedback.
							Please feel free to send us any additional dummy texts.</p>
						<p>Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit </p>

						 <a class="close-reveal-modal">&#215;</a>
					</div>
		</div>
		<br/>
		<form style="display:none;" id="checkoutForm" method="get" action="index.php?option=com_virtuemart&page=checkout.quickpay">
			<input type="hidden" name="checkout_last_step" value="4" />
			<input type="hidden" name="checkout_this_step[]" value="CHECK_OUT_GET_FINAL_CONFIRMATION" />
			<input type="hidden" name="customer_note" value="" />
			<input type="hidden" name="formSubmit" value="Confirm Order" />
			<input type="hidden" name="func" value="checkoutProcess" />
			<input type="hidden" name="payment_method_id" value="2" />
			<input type="hidden" id="hidden-userid" name="user_id" value="" />
			<input type="hidden" id="hidden-ship_to_info_id" name="ship_to_info_id" value="" />
			<input type="hidden" name="shipping_rate_id" value="" />
			<input type="hidden" name="zone_qty" value="1" />
			<input type="hidden" id="hidden-total" name="total" value="" />
			<input type="hidden" id="hidden-subtotal" name="sub_total" value="" />
		</form>
		<a id="bt_tilBetaling" style="cursor:pointer"><img src="<?php echo JURI::base() ?>templates/rhuk_milkyway/images/bt_tilBetaling.png" alt=""/></a>
	</div>
	<div id="ha-temp" style="display:none;"></div>
	<div class="clr"></div>
</div>
